let app = getApp()
Component({
    properties: {
 
      },
      data:{
        choosed: !1,
        hideAuthInfo:false,
        distributionPic:'https://tj.hjgsys.com/addons/yb_shopv2_video/core/public/upload/1/1/477d260b32aed08613dcca0aa16c523a.png'
      },
    lifetimes: {
        attached: function () {
             this.setData({
              getGlobalColor:app.globalData.globalColor,
              distributionPic:wx.getStorageSync('distribution').apply_pic
             })
             var is_check=wx.getStorageSync('distribution').is_check;
             if(is_check==2||is_check==3){
               this.setData({
                 hideAuthInfo:true
               })
             }
       }
      },
    methods: {
      applyxieyi:function(){
        wx.navigateTo({ 
          url: '/yb_shopv2/native/all/index?type=distribution_agreement',
       })
      },
      choosed:function(){
        this.setData({
          choosed: !0
        })
      },
      namechange:function(e){
        this.setData({
          name:e.detail.value
         })
      },
      mobilechange:function(e){
        this.setData({
          mobile:e.detail.value
         })
      },
      applysubmit:function(){
        var that=this
         if(!this.data.choosed){
          wx.showToast({
            title: '请先同意申请协议',
            icon: 'none',
            duration: 1500
          })
         }else{
          console.log(this.data.hideAuthInfo)
          if(this.data.hideAuthInfo==false){
            if(typeof(that.data.name)!='undefined'&&typeof(that.data.mobile)!='undefined'&&that.data.name!=''&&that.data.mobile!='')
            {
              wx.request({
                url: app.globalData.siteroot,
                data: {
                  do:'Distribution_applyDistributionUser',
                  name:that.data.name,
                  mobile:that.data.mobile,
                  user_id:wx.getStorageSync('user_id'),
                },
                success: function(res) {
                  if(res.data.code==0){
                    wx.showToast({
                      title: res.data.msg,
                      icon: 'none',
                      duration: 1500
                    })
                  }else{
                    wx.showToast({
                      title: res.data.msg,
                      icon: 'none',
                      duration: 1500
                    })
                    wx.redirectTo({
                      url: '/yb_shopv2/native/all/index?type=page_distribution',
                    })
                  }
                   
                }
              })
            }
          }else{
            wx.request({
              url: app.globalData.siteroot,
              data: {
                do:'Distribution_applyDistributionUser',
                user_id:wx.getStorageSync('user_id'),
              },
              success: function(res) {
                if(res.data.code==0){
                  wx.showToast({
                    title: res.data.msg,
                    icon: 'none',
                    duration: 1500
                  })
                }else{
                  wx.showToast({
                    title: res.data.msg,
                    icon: 'none',
                    duration: 1500
                  })
                  wx.redirectTo({
                    url: '/yb_shopv2/native/all/index?type=page_distribution',
                  })
                }
              
               
              }
            })
          }
         }
      }
    }
});
